package com.zhuifeng.product.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.zhuifeng.common.core.domain.R;
import com.zhuifeng.product.domain.Centre;
import com.zhuifeng.product.service.ICentreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhuifeng.common.log.annotation.Log;
import com.zhuifeng.common.log.enums.BusinessType;
import com.zhuifeng.common.security.annotation.RequiresPermissions;

import com.zhuifeng.common.core.web.controller.BaseController;
import com.zhuifeng.common.core.web.domain.AjaxResult;
import com.zhuifeng.common.core.utils.poi.ExcelUtil;
import com.zhuifeng.common.core.web.page.TableDataInfo;

/**
 * 个人中心表Controller
 * 
 * @author zhuifeng
 * @date 2022-08-24
 */
@RestController
@RequestMapping("/centre")
public class CentreController extends BaseController
{
    @Autowired
    private ICentreService centreService;

    /**
     * 查询个人中心表列表
     */
    @RequiresPermissions("system:centre:list")
    @GetMapping("/list")
    public TableDataInfo list(Centre centre)
    {
        startPage();
        List<Centre> list = centreService.selectCentreList(centre);
        return getDataTable(list);
    }

    /**
     * 导出个人中心表列表
     */
    @RequiresPermissions("system:centre:export")
    @Log(title = "个人中心表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Centre centre)
    {
        List<Centre> list = centreService.selectCentreList(centre);
        ExcelUtil<Centre> util = new ExcelUtil<Centre>(Centre.class);
        util.exportExcel(response, list, "个人中心表数据");
    }

    /**
     * 获取个人中心表详细信息
     */
    @RequiresPermissions("system:centre:query")
    @GetMapping(value = "/{centreId}")
    public AjaxResult getInfo(@PathVariable("centreId") String centreId)
    {
        return AjaxResult.success(centreService.selectCentreByCentreId(centreId));
    }

    /**
     * 新增个人中心表
     */
    @RequiresPermissions("system:centre:add")
    @Log(title = "个人中心表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Centre centre)
    {
        return toAjax(centreService.insertCentre(centre));
    }

    /**
     * 修改个人中心表
     */
    @RequiresPermissions("system:centre:edit")
    @Log(title = "个人中心表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Centre centre)
    {
        return toAjax(centreService.updateCentre(centre));
    }

    /**
     * 删除个人中心表
     */
    @RequiresPermissions("system:centre:remove")
    @Log(title = "个人中心表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{centreIds}")
    public AjaxResult remove(@PathVariable String[] centreIds)
    {
        return toAjax(centreService.deleteCentreByCentreIds(centreIds));
    }
}
